package com.gl.rent;

import com.haixiaoke.saas.repository.core.AjaxResult;
import com.haixiaoke.saas.repository.core.BaseController;
import com.haixiaoke.saas.repository.core.page.TableDataInfo;
import com.haixiaoke.saas.repository.pojo.TimeRange;
import com.haixiaoke.saas.repository.service.ITimeRangeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 时间区间Controller
 *
 * @author zhiping
 * @date 2023-04-11
 */
@RestController
@RequestMapping("/base/timeRange")
public class TimeRangeController extends BaseController {

    @Autowired
    private ITimeRangeService timeRangeService;

    /**
     * 查询时间区间列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TimeRange timeRange) {
        startPage();
        List<TimeRange> list = timeRangeService.selectTimeRangeList(timeRange);
        return getDataTable(list);
    }


    /**
     * 获取时间区间详细信息
     */
    @GetMapping(value = "/{timeRangeId}")
    public AjaxResult getInfo(@PathVariable("timeRangeId") Long timeRangeId) {
        return success(timeRangeService.selectTimeRangeByTimeRangeId(timeRangeId));
    }

    /**
     * 新增时间区间
     */
    @PostMapping
    public AjaxResult add(@RequestBody TimeRange timeRange) {
        return toAjax(timeRangeService.insertTimeRange(timeRange));
    }

    /**
     * 修改时间区间
     */
    @PutMapping
    public AjaxResult edit(@RequestBody TimeRange timeRange) {
        return toAjax(timeRangeService.updateTimeRange(timeRange));
    }

    /**
     * 删除时间区间
     */
    @DeleteMapping("/{timeRangeIds}")
    public AjaxResult remove(@PathVariable Long[] timeRangeIds) {
        return toAjax(timeRangeService.deleteTimeRangeByTimeRangeIds(timeRangeIds));
    }
}
